/**
 * 
 */
package com.eagle.coders.common.ui.form.renderer;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.eagle.coders.common.bean.annotations.Password;
import com.eagle.coders.common.bean.annotations.PropertyConstraints;
import com.eagle.coders.common.bean.annotations.RadioButton;
import com.eagle.coders.common.bean.annotations.RadioButtons;
import com.eagle.coders.common.bean.annotations.ResourceKey;
import com.eagle.coders.common.bean.annotations.TableColumn;
import com.eagle.coders.common.bean.annotations.TableColumns;
import com.eagle.coders.common.bean.annotations.TargetDisplayingComponent;
import com.eagle.coders.common.bean.annotations.TargetDisplayingComponents;
import com.eagle.coders.common.bean.annotations.TextArea;
import com.eagle.coders.common.bean.annotations.UIComponentInterbinding;
import com.eagle.coders.common.bean.annotations.UiComponentPosition;
import com.eagle.coders.common.bean.annotations.UnBound;
import com.eagle.coders.common.bean.annotations.type.ComponentsIdentionType;
import com.eagle.coders.common.bean.annotations.type.MandatoryType;
import com.eagle.coders.common.bean.annotations.type.NullConstraintType;
import com.eagle.coders.common.bean.annotations.type.PasswordEncryptionType;
import com.eagle.coders.common.bean.annotations.type.TextFiledInputDataType;
import com.eagle.coders.common.form.annotations.type.UIComponentType;
import com.eagle.coders.common.ui.form.renderer.cache.ComboboxDisplayBean;
import com.eagle.coders.common.ui.form.renderer.cache.PropertyConstraintsBean;
import com.eagle.coders.common.ui.form.renderer.cache.TableInfoBean;
import com.eagle.coders.common.ui.form.renderer.cache.UIDomainPropertyBean;
import com.eagle.coders.core.type.AnnotationRetrivalType;

/**
 * @author Anees
 * 
 */
public class BeansAnnotationProcessor {

	/**
	 * 
	 * @param annotations
	 * @param propertyName
	 * @param method
	 */
	public static UIDomainPropertyBean processAnnotation(String propertyName,
			Method method) {

		UIDomainPropertyBean propertiesHolder = new UIDomainPropertyBean();

		if (!method.isAnnotationPresent(UnBound.class)) {

			/* ==== FOR CONSTRAINTs ==== */
			if (method.isAnnotationPresent(PropertyConstraints.class)
					|| method.isAnnotationPresent(Id.class)) {
				boolean isMandatory = false;
				if (method.isAnnotationPresent(Id.class))
					isMandatory = true;

				PropertyConstraintsBean holder = processConstraintAnnotation(
						method.getAnnotation(PropertyConstraints.class),
						isMandatory);

				processConstraintDataType(method, holder);

				propertiesHolder.setConstraints(holder);
			}

			if (method.isAnnotationPresent(RadioButtons.class)
					|| method.isAnnotationPresent(RadioButton.class)
					|| method.isAnnotationPresent(TextArea.class)) {

				if (method.isAnnotationPresent(RadioButton.class)) {
					propertiesHolder
							.setUiPropertyType(UIComponentType.COMPNENT_RADIOBUTTON
									.getValue());
					String pName = getLabelNameFromMethod(method);
					propertiesHolder.setUiPropertyLabel(pName);
					propertiesHolder.setUiProperty(pName);
					List<UIDomainPropertyBean> radioButtonHolder = new ArrayList<UIDomainPropertyBean>();
					RadioButton radioButton = method
							.getAnnotation(RadioButton.class);
					processRadioButton(radioButton, radioButtonHolder);
					propertiesHolder
							.setDomainPropertyHolderList(radioButtonHolder);
				}

				if (method.isAnnotationPresent(RadioButtons.class)) {
					propertiesHolder
							.setUiPropertyType(UIComponentType.COMPNENT_RADIOBUTTON
									.getValue());
					String pName = getLabelNameFromMethod(method);
					propertiesHolder.setUiPropertyLabel(pName);
					propertiesHolder.setUiProperty(pName);
					RadioButtons radioButtons = method
							.getAnnotation(RadioButtons.class);
					RadioButton[] radioButton = radioButtons.values();
					processRadioButtonArray(radioButton, propertiesHolder);
				}

				if (method.isAnnotationPresent(TextArea.class)) {
					TextArea textArea = method.getAnnotation(TextArea.class);
					String name = getLabelNameFromMethod(method);
					propertiesHolder.setUiPropertyLabel(name);
					propertiesHolder.setUiProperty(name);
					propertiesHolder.setTextAreaRow(Integer.parseInt(textArea
							.rows()));
					propertiesHolder.setTextAreaColumns(Integer
							.parseInt(textArea.columns()));
					propertiesHolder
							.setUiPropertyType(UIComponentType.COMPONENT_TEXTAREA
									.getValue());

				}

			} else {
				String pName = getLabelNameFromMethod(method);
				
				processByReturnType(method, propertiesHolder,
						pName);
			}

			if (method.isAnnotationPresent(UIComponentInterbinding.class)) {
				UIComponentInterbinding interCompBinding = method
						.getAnnotation(UIComponentInterbinding.class);
				processUIComponentInterbinding(interCompBinding,
						propertiesHolder);
			}

			if (method.isAnnotationPresent(Column.class)) {
				Column column = method.getAnnotation(Column.class);
				processColumn(column, propertiesHolder);
			}

			if (method.isAnnotationPresent(OneToMany.class)) {
				OneToMany oneToMany = method.getAnnotation(OneToMany.class);
				processOneToMany(oneToMany, propertiesHolder, method);
			}

			if (method.isAnnotationPresent(ManyToOne.class)) {
				ManyToOne manyToOne = method.getAnnotation(ManyToOne.class);
				processManyToOne(manyToOne, propertiesHolder, method);
			}
			
			if(method.isAnnotationPresent(Enumerated.class)){
				Enumerated enumerated = method.getAnnotation(Enumerated.class);
				processEnumeration(enumerated, propertiesHolder, method);
			}
			
			if (method.isAnnotationPresent(OneToOne.class)) {
				OneToOne oneToOne = method.getAnnotation(OneToOne.class);
				processOneToOne(oneToOne, propertiesHolder, method);
			}

			if (method.isAnnotationPresent(ManyToMany.class)) {
				ManyToMany manyToMany = method.getAnnotation(ManyToMany.class);
				processManyToMany(manyToMany, propertiesHolder, method);
			}

			if (method.isAnnotationPresent(UiComponentPosition.class)) {
				UiComponentPosition uiComponentPosition = method
						.getAnnotation(UiComponentPosition.class);
				processUiComponentPosition(uiComponentPosition,
						propertiesHolder);
			}
			
			/* === To Set the Resource key associated with the method to support I18 === */
			if(method.isAnnotationPresent(ResourceKey.class)){
				ResourceKey resourceKey = method.getAnnotation(ResourceKey.class);
				propertiesHolder.setResourceKey(resourceKey.key());
			}

			// TODO: for static presentation

			if (method.isAnnotationPresent(Transient.class)) {
				propertiesHolder.setQuerable(false);
			}
			propertiesHolder.setDomainProperty(propertyName);
		}
		
		return propertiesHolder;
	}

	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processUIComponentInterbinding(
			UIComponentInterbinding interCompBinding,
			UIDomainPropertyBean propertiesHolder) {

		propertiesHolder.setDependentProperty(interCompBinding.childProperty());
		propertiesHolder.setParentProperty(interCompBinding.parentProperty());

	}

	/**
	 * 
	 * @param propertyConstraint
	 * @return PropertyConstraintsHolder
	 */
	private static PropertyConstraintsBean processConstraintAnnotation(
			PropertyConstraints propertyConstraint, boolean isMandatory) {

		PropertyConstraintsBean holder = new PropertyConstraintsBean();
		boolean isMandatoryConstraint = isMandatory;
		if (!isMandatory) {
			MandatoryType mandatoryType = propertyConstraint.isMandatory();
			if (mandatoryType.equals(MandatoryType.TURE)) {
				isMandatoryConstraint = true;
			} else {
				isMandatoryConstraint = false;
			}
		}

		if (isMandatoryConstraint) {
			holder.setIsMadatory(isMandatoryConstraint);
			holder.setAllowNull(false);
		}

		if (null != propertyConstraint) {
			if (propertyConstraint.allowNull().equals(
					NullConstraintType.NOTALLOWED)) {
				holder.setAllowNull(false);
			}

			holder.setTextInputDataType(propertyConstraint.textInputDataType());
			holder.setInputCaseType(propertyConstraint.inputCaseType());

			if (!"".equals(propertyConstraint.minLength()))
				holder.setMinLength(Integer.parseInt(propertyConstraint
						.minLength()));

			if (!"".equals(propertyConstraint.maxLength()))
				holder.setMaxLength(Integer.parseInt(propertyConstraint
						.maxLength()));

			holder.setPatternForValidate(propertyConstraint.pattern());
		}

		return holder;
	}

	/**
	 * 
	 * @param method
	 * @param holder
	 */
	private static void processConstraintDataType(Method method,
			PropertyConstraintsBean holder) {

		if (method.getReturnType().equals(String.class)) {
			// do nothing
		} else if (method.getReturnType().equals(Integer.class) || method.getReturnType().equals(Double.class) || method.getReturnType().equals(Float.class) ) {
			holder.setTextInputDataType(TextFiledInputDataType.ONLYNUMBER);
		} else if (method.getReturnType().equals(BigDecimal.class)) {
			holder.setTextInputDataType(TextFiledInputDataType.NUMBER_WITH_PRECSION);
		} else if (method.getReturnType().equals(Float.class)) {
			holder.setTextInputDataType(TextFiledInputDataType.NUMBER_WITH_PRECSION);
		} else if (method.getReturnType().equals(Date.class)) {
			holder.setTextInputDataType(TextFiledInputDataType.ALPHANUMERIC);
		}
	}

	/**
	 * 
	 * @param radioButton
	 * @param propertiesHolder
	 */
	private static void processRadioButtonArray(RadioButton[] radioButton,
			UIDomainPropertyBean propertiesHolder) {
		List<UIDomainPropertyBean> radioButtonHolder = new ArrayList<UIDomainPropertyBean>();
		for (RadioButton radioBtn : radioButton) {
			processRadioButton(radioBtn, radioButtonHolder);
		}
		propertiesHolder.setDomainPropertyHolderList(radioButtonHolder);
	}

	/**
	 * 
	 * @param radioButton
	 */
	private static void processRadioButton(RadioButton radioButton,
			List<UIDomainPropertyBean> radioButtonHolder) {
		UIDomainPropertyBean holder = new UIDomainPropertyBean();
		holder.setUiPropertyType(UIComponentType.COMPNENT_RADIOBUTTON
				.getValue());
		holder.setUiPropertyLabel(radioButton.label());
		holder.setRadioButtonChoice(radioButton.choice());
		radioButtonHolder.add(holder);
	}

	/**
	 * 
	 * @param method
	 * @return
	 */
	private static String getLabelNameFromMethod(Method method) {
		String name = method.getName().substring(3, method.getName().length());
		String pName = name.replaceFirst(name.substring(0, 1),
				name.substring(0, 1).toLowerCase());
//				name.substring(0, 1).toUpperCase());
		return pName;
	}

	/**
	 * 
	 * @param returnType
	 * @param propertyHolder
	 */
//	public static void processByReturnType(Class<?> returnType,
//			UIDomainPropertyBean propertiesHolder, String name) {
		
	public static void processByReturnType(Method method,
			UIDomainPropertyBean propertiesHolder, String name) {
		
		Class<?> returnType = method.getReturnType();
//		System.out.println("[Renderer][BeanAnnotationProcessor] ::setUiProperty :: name :: "+name);
		
		propertiesHolder.setUiPropertyLabel(name);
		propertiesHolder.setUiProperty(name);
		if (returnType.equals(String.class)) {
			if(method.isAnnotationPresent(Password.class)){
				Password password = method.getAnnotation(Password.class);
				PasswordEncryptionType encryptionType = password.encryption();
				String encryption = encryptionType.getValue();
				propertiesHolder
				.setUiPropertyType(UIComponentType.COMPNENT_PASSWORD
						.getValue());
				propertiesHolder.setPasswordEncryption(encryption);
			}else
				propertiesHolder
					.setUiPropertyType(UIComponentType.COMPNENT_TEXTFIELD
							.getValue());
		} else if (returnType.equals(Integer.class) || returnType.equals(Double.class) || returnType.equals(Float.class)) {

			propertiesHolder
					.setUiPropertyType(UIComponentType.COMPONENT_FMT_NUM
							.getValue());
			PropertyConstraintsBean constraintHolder = new PropertyConstraintsBean();
			processConstraintDataType(method, constraintHolder);
			propertiesHolder.setConstraints(constraintHolder);
		} else if (returnType.equals(Boolean.class)) {
			propertiesHolder
					.setUiPropertyType(UIComponentType.COMPONENT_CHECKBOX
							.getValue());
		} else if (returnType.equals(Date.class)) {
			propertiesHolder.setUiPropertyType(UIComponentType.COMPONENT_DATE
					.getValue());
		}
		// else if( returnType.equals(IUiComponent.class)){
		//
		// propertiesHolder.setUiPropertyLabel(null);
		//
		// propertiesHolder.setUiProperty(null);
		//
		// propertiesHolder.setUiPropertyType(UIComponentType.COMPNENT_PANEL.getValue());
		// }

	}

	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processColumn(Column column,
			UIDomainPropertyBean propertiesHolder) {
		propertiesHolder.setSize(column.length());
	}

	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processOneToMany(OneToMany oneToManyRelation,
			UIDomainPropertyBean propertiesHolder, Method method) {
		String name = getClassName(oneToManyRelation.targetEntity());

		if (null != name) {
			propertiesHolder.setRelationshipClassProperty(oneToManyRelation
					.targetEntity());
		} else {
			name = getClassName(method.getReturnType());
			propertiesHolder.setRelationshipClassProperty(method
					.getReturnType());
		}
		propertiesHolder.setUiPropertyLabel(name);
		propertiesHolder.setTargetClazzName(oneToManyRelation.targetEntity().getName());
		
////		======================================= START FOR TABLE COLUMN ANNOTATION ======================================
//		if(method.isAnnotationPresent(TableColumns.class) || method.isAnnotationPresent(TableColumn.class)){
//			
//			if(method.isAnnotationPresent(TableColumns.class)){
//				
//				TableColumns tableColumns = method.getAnnotation(TableColumns.class);
//				TableColumn[] columnArray = tableColumns.tableColumn();
//				for(TableColumn tableColumn : columnArray){
//					processTableColumnAnnotation(tableColumn);		
//				}
//				
//				
//			}else if(method.isAnnotationPresent(TableColumn.class)){
//				TableColumn tableColumn = method.getAnnotation(TableColumn.class);
//				processTableColumnAnnotation(tableColumn);
//			}
//		}
////		======================================= END FOR TABLE COLUMN ANNOTATION ======================================
		
		processTableColumns(method, propertiesHolder);
		
		if (null == propertiesHolder.getUiPropertyType()) {
			propertiesHolder.setUiPropertyType(UIComponentType.COMPNENT_TABLE
					.getValue());
		}
	}

	/**
	 * 
	 * @param enumerated
	 * @param propertiesHolder
	 * @param method
	 */
	public static void processEnumeration(Enumerated enumerated, UIDomainPropertyBean propertiesHolder, Method method ){
		
			String name = getClassName(method.getReturnType());

			propertiesHolder.setRelationshipClassProperty(method
					.getReturnType());

			propertiesHolder.setTargetClazzName(method.getReturnType().getName());
			propertiesHolder.setUiPropertyLabel(name);

			propertiesHolder.setTargetEnumerated(true);
			Enumerated enumerate  = method.getAnnotation(Enumerated.class);
			EnumType enumType = enumerate.value();
			propertiesHolder.setEnumType(enumType.toString());

			processTargetDisplayingComponents(method, propertiesHolder);
			
			if (null == propertiesHolder.getUiPropertyType()) {
				propertiesHolder
						.setUiPropertyType(UIComponentType.COMPNENT_COMBOBOX
								.getValue());
			}

	}
	
	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processManyToOne(ManyToOne manyToOneRelation,
			UIDomainPropertyBean propertiesHolder, Method method) {
		String name = getClassName(manyToOneRelation.targetEntity());
		if (null != name) {
			propertiesHolder.setRelationshipClassProperty(manyToOneRelation
					.targetEntity());
		} else {
			name = getClassName(method.getReturnType());
			propertiesHolder.setRelationshipClassProperty(method
					.getReturnType());
		}
		propertiesHolder.setUiPropertyLabel(name);
		propertiesHolder.setTargetClazzName(manyToOneRelation.targetEntity().getName());
		
		processTargetDisplayingComponents(method, propertiesHolder);
		
		if(method.isAnnotationPresent(Enumerated.class)){
			propertiesHolder.setTargetEnumerated(true);
			Enumerated enumerated  = method.getAnnotation(Enumerated.class);
			EnumType enumType = enumerated.value();
			propertiesHolder.setEnumType(enumType.toString());
		}
		
		if (null == propertiesHolder.getUiPropertyType()) {
			propertiesHolder
					.setUiPropertyType(UIComponentType.COMPNENT_COMBOBOX
							.getValue());
		}
	}
	
	/**
	 * 
	 * @param method
	 * @param propertiesHolder
	 */
	private static void processTableColumns(Method method, UIDomainPropertyBean propertiesHolder){
		if(method.isAnnotationPresent(TableColumns.class) || method.isAnnotationPresent(TableColumn.class)){
			List<TableInfoBean> tableInfoBeanList = new ArrayList<TableInfoBean>();
			if(method.isAnnotationPresent(TableColumns.class)){
				
				TableColumns tableColumns = method.getAnnotation(TableColumns.class);
				TableColumn[] columnArray = tableColumns.tableColumn();
				for(TableColumn tableColumn : columnArray){
					tableInfoBeanList.add(processTableColumnAnnotation(tableColumn));		
				}
			}else if(method.isAnnotationPresent(TableColumn.class)){
				TableColumn tableColumn = method.getAnnotation(TableColumn.class);
				tableInfoBeanList.add(processTableColumnAnnotation(tableColumn));
			}
			propertiesHolder.setTableInfoBeanList(tableInfoBeanList);
		}
	}
	
	/**
	 * 
	 * @param tableColumn
	 */
	private static TableInfoBean processTableColumnAnnotation(TableColumn tableColumn){
		TableInfoBean tableInfoBean = new TableInfoBean();
		tableInfoBean.setComponentType(tableColumn.componentType());
		tableInfoBean.setPosition(tableColumn.columnPosition());
		tableInfoBean.setProperty(tableColumn.property());
		tableInfoBean.setTargetBean(tableColumn.targetBean());
		return tableInfoBean;
	}


	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processOneToOne(OneToOne oneToOneRelation,
			UIDomainPropertyBean propertiesHolder, Method method) {
		String name = getClassName(oneToOneRelation.targetEntity());
		if (null != name) {
			propertiesHolder.setRelationshipClassProperty(oneToOneRelation
					.targetEntity());
		} else {
			name = getClassName(method.getReturnType());
			propertiesHolder.setRelationshipClassProperty(method
					.getReturnType());
		}
		propertiesHolder.setUiPropertyLabel(name);
		propertiesHolder.setTargetClazzName(oneToOneRelation.targetEntity().getName());
		if (null == propertiesHolder.getUiPropertyType()) {
			propertiesHolder
					.setUiPropertyType(UIComponentType.COMPNENT_TEXTFIELD
							.getValue());
		}

	}

	/**
	 * 
	 * @param propertiesHolder
	 */
	public static void processManyToMany(ManyToMany manyToManyRelation,
			UIDomainPropertyBean propertiesHolder, Method method) {
		String name = getClassName(manyToManyRelation.targetEntity());
		if (null != name) {
			propertiesHolder.setRelationshipClassProperty(manyToManyRelation
					.targetEntity());
		} else {
			name = getClassName(method.getReturnType());
			propertiesHolder.setRelationshipClassProperty(method
					.getReturnType());
		}
		propertiesHolder.setUiPropertyLabel(name);
		propertiesHolder.setTargetClazzName(manyToManyRelation.targetEntity().getName());
		
////		======================================= START FOR TABLE COLUMN ANNOTATION ======================================
//		if(method.isAnnotationPresent(TableColumns.class) || method.isAnnotationPresent(TableColumn.class)){
//			
//			if(method.isAnnotationPresent(TableColumns.class)){
//				
//				TableColumns tableColumns = method.getAnnotation(TableColumns.class);
//				TableColumn[] columnArray = tableColumns.tableColumn();
//				for(TableColumn tableColumn : columnArray){
//					processTableColumnAnnotation(tableColumn);		
//				}
//				
//				
//			}else if(method.isAnnotationPresent(TableColumn.class)){
//				TableColumn tableColumn = method.getAnnotation(TableColumn.class);
//				processTableColumnAnnotation(tableColumn);
//			}
//		}
////		======================================= END FOR TABLE COLUMN ANNOTATION ======================================

		processTableColumns(method, propertiesHolder);
		
		if (null == propertiesHolder.getUiPropertyType()) {
			propertiesHolder.setUiPropertyType(UIComponentType.COMPNENT_TABLE
					.getValue());
		}
	}
	
	/**
	 * 
	 * @param method
	 * @param propertiesHolder
	 */
	private static void processTargetDisplayingComponents(Method method, UIDomainPropertyBean propertiesHolder){
		if(method.isAnnotationPresent(TargetDisplayingComponents.class)){
			TargetDisplayingComponents targetDisplayingComponents = method.getAnnotation(TargetDisplayingComponents.class);
			ComponentsIdentionType identionType = targetDisplayingComponents.indention();
			ComboboxDisplayBean comboboxDisplayBean = new ComboboxDisplayBean();
			comboboxDisplayBean.setIdentionType(identionType.toString());
			TargetDisplayingComponent[] targetDisplayingComponentsArray = targetDisplayingComponents.targetComponent();
			
			for(TargetDisplayingComponent targetDisplayingComponent : targetDisplayingComponentsArray){
				processTargetDisplayingComponent(targetDisplayingComponent, comboboxDisplayBean);
			}
			propertiesHolder.setComboboxDisplayBean(comboboxDisplayBean);
		}else if(method.isAnnotationPresent(TargetDisplayingComponent.class)){
			TargetDisplayingComponent targetDisplayingComponent = method.getAnnotation(TargetDisplayingComponent.class);
			ComponentsIdentionType identionType = ComponentsIdentionType.SPACE;
			ComboboxDisplayBean comboboxDisplayBean = new ComboboxDisplayBean();
			comboboxDisplayBean.setIdentionType(identionType.toString());
			processTargetDisplayingComponent(targetDisplayingComponent, comboboxDisplayBean);
			propertiesHolder.setComboboxDisplayBean(comboboxDisplayBean);
		}
	}
	
	/**
	 * 
	 * @param targetDisplayingComponent
	 * @param propertiesHolder
	 */
	private static void processTargetDisplayingComponent(TargetDisplayingComponent targetDisplayingComponent,
			ComboboxDisplayBean comboboxDisplayBean){
		String componentName = targetDisplayingComponent.name();
		Integer position = Integer.parseInt(targetDisplayingComponent.position());
		comboboxDisplayBean.setDisplayComponentMap(position, componentName);
	}

	/**
	 * 
	 * @param compPosition
	 * @param propertiesHolder
	 */
	public static void processUiComponentPosition(
			UiComponentPosition compPosition,
			UIDomainPropertyBean propertiesHolder) {
		if (null == propertiesHolder.getUiPositionRow())
			propertiesHolder.setUiPositionRow(Integer.parseInt(compPosition
					.positionRow()));
		if (null == propertiesHolder.getUiPositionColumn())
			propertiesHolder.setUiPositionColumn(compPosition.positionColumn());
		if (!compPosition.tableDisplayColumn().equals("-1")) {
			propertiesHolder.setTableDisplayPosition(Integer
					.parseInt(compPosition.tableDisplayColumn()));
		}
	}
	/**
	 * 
	 * @param c
	 * @return
	 */
	public static String getClassName(Class<? extends Object> c) {
		String fQClassName = c.getName();
		int firstChar;
		firstChar = fQClassName.lastIndexOf('.') + 1;
		if (firstChar > 0) {
			fQClassName = fQClassName.substring(firstChar);
		}
		return fQClassName;
	}
	
	/**
	 * 
	 * @param beanClass
	 * @return
	 */
	public static String getClassName(String beanClass){
		String fQClassName = beanClass;
		int firstChar;
		firstChar = fQClassName.lastIndexOf('.') + 1;
		if (firstChar > 0) {
			fQClassName = fQClassName.substring(firstChar);
		}
		return fQClassName;
	}
	
	/**
	 * 
	 * @param beanClass
	 * @param retrivalType
	 * @return
	 */
	public static Map<String, Object> getValueOfNamedAnnotation(String beanClass, AnnotationRetrivalType retrivalType){
		Map<String, Object> map = new HashMap<String, Object>();
		try{
			Class<?> clzz = Thread.currentThread().getContextClassLoader().loadClass(beanClass);
			if(retrivalType.toString().equals(AnnotationRetrivalType.TABLE.toString())){
				if(clzz.isAnnotationPresent(Table.class)){
					Table table= clzz.getAnnotation(Table.class);
					map.put("beanTableName", table.name());
				}
			}
		}catch(ClassNotFoundException cne){
			cne.printStackTrace();
		}
		return map;
	}
}